package com.cloudcreativity.blyg.sqlite;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "CATEGORY_TWO".
*/
public class CategoryTwoDao extends AbstractDao<CategoryTwo, Long> {

    public static final String TABLENAME = "CATEGORY_TWO";

    /**
     * Properties of entity CategoryTwo.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, long.class, "id", true, "_id");
        public final static Property Name = new Property(1, String.class, "name", false, "NAME");
        public final static Property CategoryOneId = new Property(2, long.class, "categoryOneId", false, "CATEGORY_ONE_ID");
    }

    private Query<CategoryTwo> categoryOne_SecondsQuery;

    public CategoryTwoDao(DaoConfig config) {
        super(config);
    }
    
    public CategoryTwoDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"CATEGORY_TWO\" (" + //
                "\"_id\" INTEGER PRIMARY KEY NOT NULL ," + // 0: id
                "\"NAME\" TEXT NOT NULL ," + // 1: name
                "\"CATEGORY_ONE_ID\" INTEGER NOT NULL );"); // 2: categoryOneId
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"CATEGORY_TWO\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, CategoryTwo entity) {
        stmt.clearBindings();
        stmt.bindLong(1, entity.getId());
        stmt.bindString(2, entity.getName());
        stmt.bindLong(3, entity.getCategoryOneId());
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, CategoryTwo entity) {
        stmt.clearBindings();
        stmt.bindLong(1, entity.getId());
        stmt.bindString(2, entity.getName());
        stmt.bindLong(3, entity.getCategoryOneId());
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.getLong(offset + 0);
    }    

    @Override
    public CategoryTwo readEntity(Cursor cursor, int offset) {
        CategoryTwo entity = new CategoryTwo( //
            cursor.getLong(offset + 0), // id
            cursor.getString(offset + 1), // name
            cursor.getLong(offset + 2) // categoryOneId
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, CategoryTwo entity, int offset) {
        entity.setId(cursor.getLong(offset + 0));
        entity.setName(cursor.getString(offset + 1));
        entity.setCategoryOneId(cursor.getLong(offset + 2));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(CategoryTwo entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(CategoryTwo entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(CategoryTwo entity) {
        throw new UnsupportedOperationException("Unsupported for entities with a non-null key");
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "seconds" to-many relationship of CategoryOne. */
    public List<CategoryTwo> _queryCategoryOne_Seconds(long categoryOneId) {
        synchronized (this) {
            if (categoryOne_SecondsQuery == null) {
                QueryBuilder<CategoryTwo> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.CategoryOneId.eq(null));
                categoryOne_SecondsQuery = queryBuilder.build();
            }
        }
        Query<CategoryTwo> query = categoryOne_SecondsQuery.forCurrentThread();
        query.setParameter(0, categoryOneId);
        return query.list();
    }

}
